"""
@Author:WKVugen
@Time:2023-07-03
@Description: excel读取工具类
"""
import openpyxl
from utils.file_reader import SheetTypeError


def read_excel(excel_path, sheet_name):
    # 工作簿
    wb = openpyxl.load_workbook(excel_path)
    # 获得sheet对象
    if type(sheet_name) not in [int, str]:
        raise SheetTypeError('Please pass in <type int> or <type str>, not {0}'.format(type(sheet_name)))
    elif type(sheet_name) == int:
        # 如果是索引，则通过索引获取sheet对象
        sn = wb.worksheets[sheet_name]
    else:
        # 如果是sheet名称，则通过名称获取sheet对象
        sn = wb[sheet_name]

    # 打印sheet最大行数和列数
    print(sn.max_row, sn.max_column)
    # 获取每一行的数据
    row_list = []
    for row in range(2, sn.max_row + 1):
        col_list = []
        for col in range(1, sn.max_column + 1):
            col_list.append(sn.cell(row, col).value)
        row_list.append(col_list)
    return row_list
    # 读取excel数据





if __name__ == '__main__':
    data = read_excel("../config/111111.xlsx", "Sheet1")
    print(data)